<?php 
class Customer extends TRecord
{ 
    const ...
    private $contacts;

    public function clearParts() 
    { 
        $this->contacts  = array(); 
    }

    public function addContact(Contact $contact) 
    { 
        $this->contacts[] = $contact; 
    } 
    
    public function getContacts() 
    { 
        return $this->contacts; 
    }

    public function load($id) 
    { 
        $contact_rep = new TRepository('Contact'); 
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $id)); 
        
        $contacts = $contact_rep->load($criteria); 
        if ($contacts) 
        { 
            foreach ($contacts as $contact) 
            { 
                $this->addContact($contact); 
            } 
        } 
        
        return parent::load($id);
    } 
    
    public function store() 
    { 
        parent::store(); 
        
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $this->id)); 
        
        $contact_rep = new TRepository('Contact'); 
        $contact_rep->delete($criteria); 
        
        if ($this->contacts) 
        { 
            foreach ($this->contacts as $contact) 
            { 
                $contact-> customer_id = $this-> id; 
                $contact->store(); 
            } 
        } 
    }
     
    public function delete($id = NULL) 
    { 
        $id = isset($id) ? $id : $this->{'id'}; 
        
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $id)); 
        
        $repository = new TRepository('Contact'); 
        $repository->delete($criteria); 
        parent::delete($id); 
    }
}
?>